package com.example.lanouhn.bantangapp.activities.activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.example.lanouhn.bantangapp.R;
import com.example.lanouhn.bantangapp.activities.adapters.VpSelectedAdapter;
import com.example.lanouhn.bantangapp.activities.fragments.Fragment_Search_SingleProduct;
import com.example.lanouhn.bantangapp.activities.fragments.Fragment_Search_item_detaieledlist;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 16/7/22.
 */
public class MainSeachActivity extends FragmentActivity {
    private ImageView back;
    private RelativeLayout re;
    private ViewPager viewPager;//vp
    private VpSelectedAdapter vpadapter;
    private TabLayout tab;
    private List<String> tabNames;
    //viewpager的数据集合
    private List<Fragment> fragments;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initview();
        initLinstener();
        initData();
        setDataToView();




    }
   //找到控件
    private void initview() {
        setContentView(R.layout.home_search_activity);
        back= (ImageView) findViewById(R.id.back);
        re= (RelativeLayout) findViewById(R.id.re);
        viewPager= (ViewPager) findViewById(R.id.viewpager);
        tab= (TabLayout)findViewById(R.id.tab);
    }
    //监听事件
    private void initLinstener() {
        //返回键
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


        //跳转热门搜索
        re.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it = new Intent(MainSeachActivity.this, ActivitySearch_hottag.class);
                startActivity(it);
            }
        });
    }
    //数据集合
    private void initData() {
        //tab标签名称集合
        tabNames = new ArrayList();
        //Fragment集合
        fragments = new ArrayList();
        //tablayout数据集合
        tabNames.add(getResources().getString(R.string.Deillist));
        tabNames.add(getResources().getString(R.string.Line));

        // 添加页面
        fragments.add(new Fragment_Search_SingleProduct());
        fragments.add(new Fragment_Search_item_detaieledlist());

    }
    //绑定数据
    private void setDataToView() {
        vpadapter = new VpSelectedAdapter(getSupportFragmentManager(),tabNames,fragments);
        //设置适配器
        viewPager.setAdapter(vpadapter);
        //tabLayout和ViewPager绑定
        tab.setupWithViewPager(viewPager);
    }
}
